<?php
ini_set('mysqli.reconnect', 'Off');
$mysqli = mysqli_init();
mysqli_real_connect($mysqli, "localhost", "root", "123456", "test");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/*

CREATE TABLE `test2` (
  `id` int(11) DEFAULT NULL,
  `username` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

*/

$query = "INSERT INTO test2 VALUES (1007, 'pcdinh4');INSERT INTO test2 VALUES (1008-, 'pcdinh5');";

/* execute multi query */
mysqli_multi_query($mysqli, $query);

if (false === mysqli_ping($mysqli))
{
    exit('Database connection is closed');
}

do
{
    /* store first result set */
    if ($result = $mysqli->store_result())
    {
        while ($row = $result->fetch_row())
        {
            var_dump($row);
        }

        $result->free();
    }
    else
    {
        var_dump(mysqli_error($mysqli));
        var_dump(mysqli_errno($mysqli));
    }

    /* print divider */
    if ($mysqli->more_results()) {
        printf("<br />-----------------<br />");
    }
} while ($mysqli->next_result());

if (mysqli_errno($mysqli) > 0)
{
    echo 'Error: '.mysqli_error($mysqli);
}

var_dump(mysqli_ping($mysqli));

/* close connection */
$mysqli->close();
?>
